package com.goal98.grails.plugin.account.services

import com.goal98.grails.plugin.account.domain.Debit
import com.goal98.grails.plugin.account.domain.Credit
import com.goal98.grails.plugin.account.domain.Account

class AccountService {

    boolean transactional = true

    def credit(Account account, BigDecimal amount, String description) {
        account.credit(amount)
        Credit credit = new Credit()
        credit.description = description
        credit.amount = amount
        account.addToTransactions(credit)
        account.save(flush:true)
    }

    def debit(Account account, BigDecimal amount, String description) {
        account.debit(amount)
        Debit debit = new Debit()
        debit.description = description
        debit.amount = amount
        account.addToTransactions(debit)
        account.save(flush:true)
    }
}
